#include "CharacterController.h"


CharacterController::CharacterController(SceneManager* sceneManager)
	: mCharacterNums(0)
	, mSceneMgr(sceneManager)
{
}


CharacterController::~CharacterController(void)
{
}

void CharacterController::createCharacter(Ogre::String characterType)
{
	if(characterType == charTypePlayer)
	{
		mCharacters.push_back(new PlayerCharacter(getCharacterNum(),charTypePlayer,mSceneMgr));
	}
}

Real CharacterController::getCharacterNum()
{
	return mCharacterNums++;
}

void CharacterController::injectKeyDownForChar(const OIS::KeyEvent& evt)
{
	for(std::list<Character*>::const_iterator loc = mCharacters.begin(); loc != mCharacters.end(); loc++)
	{
		if((*loc)->mCharType == charTypePlayer)
		{
			((PlayerCharacter*)(*loc))->injectKeyDown(evt);
		}
	}
}

void CharacterController::injectKeyUpForChar(const OIS::KeyEvent& evt)
{
	for(std::list<Character*>::const_iterator loc = mCharacters.begin(); loc != mCharacters.end(); loc++)
	{
		if((*loc)->mCharType == charTypePlayer)
		{
			((PlayerCharacter*)(*loc))->injectKeyUp(evt);
		}
	}
}

void CharacterController::updateCharacters(Real deltaTime)
{
	for(std::list<Character*>::const_iterator loc = mCharacters.begin(); loc != mCharacters.end(); loc++)
	{
		(*loc)->update(deltaTime);
	}
}
